package com.android.vgongyi.common;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.vgongyi.R;
import com.android.vgongyi.activity.FavoriteActivity;
import com.android.vgongyi.activity.HomeActivity;
import com.android.vgongyi.activity.InfoActivity;
import com.android.vgongyi.activity.SettingActivity;

/**
  * click listener for the tabs of direction bar
  */
public class onMenuChangedListener implements OnClickListener{	
		
		private Activity activity;
		
		public onMenuChangedListener(Activity activity) {
			this.activity = activity;
		}
		
		public void onClick(View v) {
			Intent intent = new Intent();
			
			switch (v.getId()) {
			case R.id.ImageView_tab0:
				if(activity instanceof HomeActivity){
					HomeActivity homeActivity = (HomeActivity)activity;
					TextView msgText = (TextView)homeActivity.findViewById(R.id.msg_count);
					int msg_count = Integer.valueOf(msgText.getText().toString());
					if(msg_count>AppConstant.NO_0) {
						homeActivity.initData();
						Log.i("msg","click home btn");
					}
					return;
				}
				intent.setClass(this.activity, HomeActivity.class);
				break;
			
			case R.id.ImageView_tab1:
				if(activity instanceof FavoriteActivity){
					return;
				}
				intent.setClass(this.activity, FavoriteActivity.class);
				break;
								
			case R.id.ImageView_tab2:
				if(activity instanceof InfoActivity){
					return;
				}
				intent.setClass(activity, InfoActivity.class);
				break;
			case R.id.ImageView_tab3:
				if(activity instanceof SettingActivity){
					return;
				}
				intent.setClass(activity, SettingActivity.class);
				break;
			}
			
			activity.startActivity(intent);
			activity.finish();
		}
		
	}